
import PayRollsAPI from '../../../../common/api/salary/payrolls/payrolls.api.js';
import doT from '../../../../../vendor/template/doT.js';
import watermark from '../../../../common/watermark.js';
import { getAuthZ, TEST_NUMBER, TEST_INFO_NUMBER, Collaboration_APP, Service_APP } from '../../../../../../public/js/config/config.js';
Utils.NameSpace('SN.Salar.PayRolls');
(function (window, document, $) {
    let _vm;
	const payrollsdetailsTemplate = doT.template($('#payrollsdetails_template').text());
	var testpr = [{
            "company": "云南神农农业产业集团股份有限公司",
            "dept": "集团总部",
            "curOU": "卓越运营中心",
            "numCode": "03356",
            "name": "李云龙",
            "jobRank": "部门经理.M3",
            "jobGrade": "11-1",
            "dt": "2023年1月",
            "totalPayable": 12345.67,
            "totalDeduction": 345.00,
            "totalPaid": 12000.67,
            "remark": "",
            "payables": [
                {
                    "n": "基本工资",
                    "v": 22200.0,
                    "s": "1.1",
                    "p": "1"
                },
                {
                    "n": "工龄工资",
                    "v": 140.0,
                    "s": "1.2",
                    "p": "1"
                },
                {
                    "n": "职称工资",
                    "v": 0.0,
                    "s": "1.3",
                    "p": "1"
                },
                {
                    "n": "绩效考核",
                    "v": 28920.0,
                    "s": "1.4",
                    "p": "1"
                },
                {
                    "n": "通讯补贴",
                    "v": 0.0,
                    "s": "1.5",
                    "p": "1"
                },
                {
                    "n": "伙食补贴",
                    "v": 0.0,
                    "s": "1.6",
                    "p": "1"
                },
                {
                    "n": "特殊工种补贴",
                    "v": 0.0,
                    "s": "1.7",
                    "p": "1"
                },
                {
                    "n": "其它补贴",
                    "v": 800.0,
                    "s": "1.8",
                    "p": "1"
                }
            ],
            "deductions": [
				{"n":"缺勤扣款","v":"0","s":"2.1","p":"2"},
				{"n":"代扣税","v":"0","s":"2.2","p":"2"},
				{"n":"养老保险个人缴费","v":"0","s":"2.3","p":"2"},
				{"n":"失业保险金个人缴费","v":"0","s":"2.4","p":"2"},
				{"n":"医疗保险个人缴费","v":"0","s":"2.5","p":"2"},
				{"n":"住房公积金个人缴存","v":"0","s":"2.6","p":"2"},
				{"n":"个人社保缴费合计","v":"0","s":"2.7","p":"2"},
				{"n":"其它扣款","v":"50","s":"2.8","p":"2"}
			],
			"others": [
				{"n":"绩效标准","v":"2000","s":"3.1","p":"3"},
				{"n":"子女教育专项扣除","v":"500","s":"3.2","p":"3"},
				{"n":"个税起征点","v":"5000","s":"3.3","p":"3"},
				{"n":"个人社保缴费合计","v":"0","s":"3.4","p":"3"},
				{"n":"累计收入","v":"0","s":"3.5","p":"3"},
				{"n":"累计基本减除费用","v":"0","s":"3.6","p":"3"},
				{"n":"医疗保险公司缴费","v":"160","s":"3.7","p":"3"},
				{"n":"失业保险公司缴费","v":"50","s":"3.8","p":"3"}
			]
        }]
	
	
	
    $(function () {
        // JS严格模式
        'use strict';
        watermarkBgImg();
		$('body').attr('data-weui-theme', 'light'); //强制光明模式
        _vm = new Vue({
            el: "#divPage",
			data() {
			    return {
					"year" : getUrlKey("Y"),
			        "month": getUrlKey("M"),
			        "period" : getUrlKey("Y") + '年' + getUrlKey("M") + '月'
			    }
			},
            async created() {
                let that = this;
                let thisYear = (new Date()).getFullYear(), resData = { bizDate: [], sumAvgPrice: [] };
                PayRollsAPI.queryPayRollsInfo(getUrlKey("Y"),getUrlKey("M"),getUrlKey("F"),getUrlKey("id")).then(async res => {
					let it = res[0];
					// it = testpr[0];
                    
					it.totalPayable = Utils.toThousands(it.totalPayable);
					it.totalDeduction = Utils.toThousands(it.totalDeduction);
					it.totalPaid = Utils.toThousands(it.totalPaid);
					it.remark = (it.remark == undefined ? "" : it.remark);
                    await it.payables.map(item => {
                       item.v =  Utils.toThousands(item.v);
                    });
					await it.deductions.map(item => {
					   item.v =  Utils.toThousands(item.v);
					});
					if(it.others != undefined) {// 检验内容为空
						await it.others.map(item => {
						   item.v =  Utils.toThousands(item.v);
						});
					}
					$('#annualInfo').empty().append(payrollsdetailsTemplate(res));
                }).catch(res => {
                    $('#annualInfo').empty().append("加载异常,请重新进入...");
                })
            }
        });
		$("#spPeriod").text(_vm.period);
    });
	
	const getUrlKey = (name) => { /** 获取地址栏的 参数  传入 字段返回值 */
	    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	    var r = window.location.search.substr(1).match(reg);
	    if (r != null) return unescape(r[2]); return null;
	}

    const watermarkBgImg = () => {
        let _userInfo = JSON.parse(Utils.GetSessionStorage("SNLoginUserInfo")) || {};
        PayRollsAPI.queryUserName(Utils.GetQueryString('state') || Collaboration_APP.sourceID).then(res => {
            watermark.set(_userInfo.curUserName + res.code);// 水印
        }).catch(_ => {
            watermark.set(_userInfo.curUserName);// 水印
        });

    }
	//返回列表界面
	$(document).on('click', '#returnPage', function (e) {
	    location.href = `payrolls.html?year=` + _vm.year;
	})
})(window, document, jQuery);
